<template>
  <div class="ele-body task-info" v-loading="loading">
    <el-row :gutter="15">
      <el-col :span="8">
        <el-card class="card" shadow="never">
          <span slot="header" class="card-title">任务详情</span>
          <div class="left-content">
            <div>
              <span>任务状态：</span>
              <span>{{ taskInfo.status_text || '' }}</span>
            </div>
<!--            <div>-->
<!--              <span>任务名称：</span>-->
<!--              <span>{{ taskInfo.name || '' }}</span>-->
<!--            </div>-->
            <div>
              <span>任务编号：</span>
              <span style="color:var(--color-primary)" >{{ taskInfo.task_number || '' }}</span>
            </div>
            <div>
              <span>任务名称：</span>
              <span>{{ taskInfo.type || '' }}</span>
            </div>
            <div>
              <span>完成设备数量：</span>
              <span>{{ taskInfo.product_count || '-- --' }}</span>
            </div>
            <div>
              <span>计划设备数量：</span>
              <span> {{ taskInfo.plan_product_quantity || '-- --' }}</span>
            </div>

            <div>
              <span>负责人：</span>
              <span>{{ formatUsers || '' }}</span>
            </div>
<!--            <div>-->
<!--              <span>任务比重：</span>-->
<!--              <span>{{ taskInfo.percent_format || '' }}</span>-->
<!--            </div>-->
            <div>
              <span>计划开始时间：</span>
              <span>{{ taskInfo.plan_start_at || '' }}</span>
            </div>
            <div>
              <span>计划结束时间：</span>
              <span>{{ taskInfo.plan_complete_at || '' }}</span>
            </div>
            <div>
              <span>实际开始时间：</span>
              <span> {{ taskInfo.start_at || '-- --' }}</span>
            </div>
            <div>
              <span>实际结束时间：</span>
              <span>{{ taskInfo.complete_at || '-- --' }}</span>
            </div>
            <div>
              <span>计划工时：</span>
              <span>{{ taskInfo.plan_work_hour || '' }}h</span>
            </div>
            <div>
              <span>实际工时：</span>
              <span>{{ taskInfo.work_hour }}h</span>
            </div>
            <div>
              <span>创建人：</span>
              <span>{{ taskInfo.logs ? taskInfo.logs[0].user_name : '' }}</span>
            </div>
            <div>
              <span>创建时间：</span>
              <span>{{ taskInfo.logs ? taskInfo.logs[0].create_time : '' }}</span>
            </div>
            <div>
              <span>所属项目：</span>
              <span>{{ taskInfo.project_name || '' }}</span>
            </div>
            <div>
              <span>所属项目编号：</span>
              <span>{{ taskInfo.project_number || '' }}</span>
            </div>
            <div>
              <span>描述说明：</span>
              <span>{{ taskInfo.description || '' }}  </span>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="16">
        <el-card class="card" shadow="never">
          <span slot="header" class="card-title">信息概览</span>
          <div class="right-content">
            <!--            <el-card class="right" shadow="never">-->
            <el-tabs lazy v-model="tabsActive">
              <el-tab-pane lazy label="动态信息" name="dtxx">
                <dynamicInfo ref="dynamicInfo" :logs="taskInfo.logs"/>
              </el-tab-pane>
              <el-tab-pane label="设备信息" name="sbxx">
                <equipmentInfo ref="equipmentInfo" :id="id"/>
              </el-tab-pane>
            </el-tabs>
            <!--            </el-card>-->
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import dynamicInfo from "@/views/project/task/info/components/dynamicInfo.vue";
import equipmentInfo from "@/views/project/task/info/components/equipmentInfo.vue";

export default {
  name: "index",
  components: {dynamicInfo, equipmentInfo},
  data() {
    return {
      id: null,
      loading: false,
      taskInfo: {},
      tabsActive: 'dtxx'
    }
  },
  watch: {
    //监听路由变化更新本地数据
    $route() {
      if (this.$route.path === '/project/task/info') {
        this.id = this.$route.query.id; //获取传来的参数
        this.loadData()
      }
    }
  },
  computed: {
    formatUsers() {
      let res = ''
      if (this.taskInfo.users) {
        res = this.taskInfo.users.map(item => {
          return item.name
        }).join(' ')
      }
      return res
    }
  },
  created() {
    this.id = this.$route.query.id; //获取传来的参数
    this.loadData();
  },
  methods: {
    loadData() {
      this.loading = true
      this.$http.get(`tasks/${this.id}`).then((res) => {
        if (res.data.success)
          this.taskInfo = res.data.data;
        else
          this.$message.error(this.data.msg)
        this.loading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">
.task-info {
  .card {
    .card-title {
      border-left: 3px solid var(--color-primary);;
      padding-left: 6px;
      font-size: 16px;
      font-weight: bold;
      color: rgb(0 0 0 / .65);

    }

    .left-content {
      overflow: auto;
      height: calc(100vh - 208px);

      > div {
        padding: 10px;
        font-size: 15px;
        display: flex;
        justify-content: space-between;
        width: 100%;
        box-sizing: border-box;

        > span:nth-child(1) {
          min-width: 105px;
        }

        > span:nth-child(2) {
          flex: 1;
          margin-left: 25px;
          word-break: break-word;
        }
      }

      > div:nth-child(1) {
        padding-top: 0;
      }
    }

    .right-content {
      overflow: auto;
      height: calc(100vh - 208px);
      font-size: 15px;

      .content-top {
        display: flex;
        justify-content: space-between;
        padding: 0 0 20px;

        > div {
          flex: 1;
        }
      }

      .content-bottom {

      }
    }
  }
}
</style>
